/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Sorting;

import DataStructuresThreads.ListThread;
import DataStructuresThreads.QueueThread;
import DataStructuresThreads.StackThread;
import DataStructuresThreads.VectorThread;

/**
 *
 * @author rafael
 */
public class ThreadAuxiliary extends Thread{
    
    private int operation;
    private String threadName;
    private StackThread stackThread;
    private QueueThread queueThread;
    private ListThread listThread;
    private VectorThread vectorThread;

    public ThreadAuxiliary(StackThread stackThread, int operation) {
        this.stackThread = stackThread;
        this.operation = operation;
        this.threadName = "stack";
    }
    
    public ThreadAuxiliary(QueueThread queueThread, int operation) {
        this.queueThread = queueThread;
        this.operation = operation;
        this.threadName = "queue";
    }
    
    public ThreadAuxiliary(ListThread listThread, int operation) {
        this.listThread = listThread;
        this.operation = operation;
        this.threadName = "list";
    }
    
    public ThreadAuxiliary(VectorThread vectorThread, int operation) {
        this.vectorThread = vectorThread;
        this.operation = operation;
        this.threadName = "vector";
    }

    @Override
    public void run() {
        
        if (threadName.equalsIgnoreCase("stack")) {
            stackOperations(operation);
        } else if (threadName.equalsIgnoreCase("queue")) {
            queueOperations(operation);
        } else if (threadName.equalsIgnoreCase("list")) {
            listOperations(operation);
        } else {
            vectorOperations(operation);
        }
        
    }
    
    public void stackOperations(int operation) {
        
        if (operation == 1) {
        StackThread.pushElement();
        } else if (operation == 2) {
        StackThread.popElement();    
        } else {
        StackThread.topElement();
        }
        
    }
    
    public void queueOperations(int operation) {
        
        if (operation == 1) {
        QueueThread.insertElement();
        } else if (operation == 2) {
        QueueThread.popElement();  
        } else {
        QueueThread.topElement();
        }
        
    }
    
    public void listOperations(int operation) {
        
        if (operation == 1) {
        ListThread.insertElement();
        } else if (operation == 2) {
        ListThread.popElement();  
        } else {
        ListThread.topElement();
        }
        
    }
    
    public void vectorOperations(int operation) {
        
        if (operation == 1) {
        VectorThread.insertElement();
        } else if (operation == 2) {
        VectorThread.popElement();  
        } else {
        VectorThread.topElement();
        }
        
    }
    
}
